{% extends "./inc/base.html" %}
{% block style %}
<link rel="stylesheet" href="/static/admin/js/zTree/zTreeStyle/zTreeStyle.css" type="text/css">
{% endblock%}
{% block content %}
<section class="vbox">
    <header class="header bg-light dk">
        <p>{{controller.meta_title}}</p>

    </header>
    <section class="scrollable wrapper">

        <div class="row">

            <div class="col-lg-12">
                <section class="panel panel-default">
                    <div class="panel-body">
                        <form action="/admin/channel/updates" class="form-horizontal" method="post"  data-validate="parsley">
                        <div class="tab-content">

                            <div id="tab1" class="tab-pane fade active in">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">上级分类</label>
                                    <div class="col-sm-10">
                                        <div class="row">
                                        <div class="col-md-3">
                                        <select class="form-control" name="pid" id="pid">
                                        </select>
                                        </div>
                                            <div class="col-md-12">
                                                <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 上级分类.</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="line line-dashed b-b line-lg pull-in"></div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">导航名称</label>
                                    <div class="col-sm-10">
                                        <div class="row">
                                        <div class="col-md-3"><input name="title" type="text" class="form-control" value="{{info.title|default('')}}" data-required="true"></div>
                                            <div class="col-md-12">
                                                <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 名称不能为空.</span>
                                        </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="line line-dashed b-b line-lg pull-in"></div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">导航链接</label>
                                    <div class="col-sm-10">
                                        <div class="row">
                                        <div class="col-md-6">
                                            <div class="input-group">
                                            <input id="selectcate" name="url" type="text" class="form-control" value="{{info.url|default('')}}" data-required="true">
                                        <span class="input-group-btn">
                            <a href="/admin/public/selectcate" data-toggle="ajaxModal" class="btn btn-default" type="button">选择分类</a>
                          </span>
                                        </div>
                                        </div>
                                            <div class="col-md-12">
                                                <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 用于调转的URL，支持带http://的URL</span>
                                        </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="line line-dashed b-b line-lg pull-in"></div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">新窗口打开</label>
                                    <div class="col-sm-10">
                                        <div class="row">
                                        <div class="col-md-3">
                                          <select class="form-control" name="target">
    				<option value="0" {%if info.target =="0" %}selected{%endif%}>否</option>
    				<option value="1" {%if info.target =="1" %}selected{%endif%}>是</option>
                                </select>
                                        </div>
                                        <div class="col-md-12">
                                            <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 是否新窗口打开链接</span>
                                        </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="line line-dashed b-b line-lg pull-in"></div>
                                <div class="form-group">
                                <label class="col-sm-2 control-label">优先级</label>
                                <div class="col-sm-10">
                                    <div class="row">
                                    <div class="col-md-2">
                                      <input name="sort" type="text" class="form-control" value="{{info.sort|default('0')}}">
                                    </div>
                                        <div class="col-md-12">
                                            <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i>  导航显示顺序</span>
                                    </div>
                                    </div>
                                </div>
                            </div>


                                <div class="line line-dashed b-b line-lg pull-in"></div>
                            </div>
                        </div>
                            <div class="form-group form-submit">
                                <div class="col-sm-4 col-sm-offset-2">
                                    {%if info.id%}
                                    <input type="hidden" name="id" value="{{info.id|default('')}}">
                                    {%endif%}
                                    <button type="submit" target-form="form-horizontal" class="btn btn-primary ajax-post">保存</button>
                                    <button type="submit" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </section>

            </div>

        </div>
    </section>
</section>

{% endblock %}

{% block script %}
<!-- slider -->
<!--<script src="/static/js/slider/bootstrap-slider.js"></script>-->
<!-- file input -->
<script src="/static/admin/js/parsley/parsley.min.js"></script>
<script src="/static/admin/js/parsley/parsley.extend.js"></script>
<script src="/static/admin/js/zTree/jquery.ztree.all-3.5.min.js" type="text/javascript"></script>
<script src="/static/admin/js/slimscroll/jquery.slimscroll.min.js"></script>
<script type="text/javascript">
    $(function(){

        //获取上级菜单
        $.ajax({
            url: "/admin/channel/getchannel",
            success: function (msg) {
                /* 展示生成的HTML */
                $("#pid").html(category_to_html(msg));

            }
        })

        /* 生成HTML ul/li 形式 */
        function category_to_html(nodes) {
            var html = [];
            var size = nodes.length;
            var left = null;
            var pid ="{{info.pid}}";
            var check = "";
            if(pid==0){
                html.push('<option value="0" selected="selected">一级导航</option>');
            }else {
                html.push('<option value="0" >一级导航</option>');
            }
            for (var i = 0; i < size; i++) {
                left = nodes[i];
                if(pid == left.id){
                    html.push('<option value="' + left['id'] +  '" selected="selected">'+new Array(left["deep"]+1).join("= ") + left['title'] +  '</option>');
                }else {
                    html.push('<option value="' + left['id'] + '">'+new Array(left["deep"]+1).join("= ") + left['title'] +  '</option>');
                }
                console.log(left.id);

            }
            return html.join("\n");
        }
    })
</script>
{% endblock %}
